#include "callbacks.h"
TaskHandle_t t1;
TaskHandle_t t2;
TaskHandle_t t3;
TaskHandle_t t4;
TaskHandle_t t5;


/******ALL customized callbacks should be here******/

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef*huart,uint16_t size)
{
  GY_Callback(huart);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  GreyCallback(GPIO_Pin);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  controlCallback(htim);
}

/**************************************************/


/********ALL thread Functions should be here********/

void Creator(void *pvParameters)
{
	delay_init();
 	OLED_Init();
	motor_control_init(&htim2,&htim3,&htim5);
  	Mot_init(&htim4);
  	GreyInit(GPIO_PIN_1);
  	GY_init(&huart4);
	xTaskCreate((TaskFunction_t)logiTask,
							(char*)"mtr_tsk",
							(uint16_t)80,
							(void*)NULL,
							(UBaseType_t)1,
							&t1);
	xTaskCreate((TaskFunction_t)idleTask,
							(char*)"bbb",
							(uint16_t)60,
							(void*)NULL,
							(UBaseType_t)0,
							&t2);
	xTaskCreate((TaskFunction_t)oled,
							(char*)"oled",
							(uint16_t)80,
							(void*)NULL,
							(UBaseType_t)1,
							&t3);
	vTaskDelete(t4);
}

//a maintance task with lower priority than any others
void idleTask(void *pvParameters)
{
	uint32_t pwt;
	while(1)
	{
		vTaskDelayUntil(&pwt,pdMS_TO_TICKS(100));
		pwt = xTaskGetTickCount();
		
	}
}

//Logic task
void logiTask(void *pvParameters)
{
	uint32_t pwt;
	while(1)
	{
		vTaskDelayUntil(&pwt,pdMS_TO_TICKS(100));
		pwt = xTaskGetTickCount();
		
	}
}

//task for OLED display or any others
void oled(void *pvParameters)
{
	uint32_t pwt;
	while(1)
	{
		vTaskDelayUntil(&pwt,pdMS_TO_TICKS(100));
		pwt = xTaskGetTickCount();
	}
}
/**************************************************/
